<?= \common\widgets\Asset::widget(['type'=>['viewer']])?>
<style>
    .layui-table-cell {
        height:auto;
        padding: unset !important;
    }
    .goods-content>div:not(:last-of-type) {
        border-bottom:1px solid #DCDCDC;
    }
    .goods-data::after{
        display: block;
        content: '';
        clear: both;
    }
    .goods_name_hide{
        overflow:hidden;
        white-space:nowrap;
        text-overflow: ellipsis;
    }

</style>
<div>
    <div class="col-sm-12 search-collapse">
        <div class="layui-card-body">
            <div class="layui-collapse like-layui-collapse" lay-accordion=""
                 style="border:1px dashed #c4c4c4">
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title like-layui-colla-title" style="background-color: #fff">操作提示<i
                                class="layui-icon layui-colla-icon"></i></h2>
                    <div class="layui-colla-content layui-show">
                        <p>*用户下单成功后，用户点击确认后，方可提现</p>
                    </div>
                </div>
            </div>
        </div>
        <form id="role-form">
            <div class="select-list">
                <ul>
                    <li class="select-time">
                        <label>下单时间： </label>
                        <?= \common\widgets\FormInput::widget(['name'=>'input','extend'=>['name'=>'between[create_time][start]','id'=>'startTime','place'=>'开始时间']])?>
                        <span>-</span>
                        <?= \common\widgets\FormInput::widget(['name'=>'input','extend'=>['name'=>'between[create_time][end]','id'=>'endTime','place'=>'结束时间']])?>
                    </li>
                    <li><?= \common\widgets\FormInput::widget(['name'=>'input|订单编号','extend'=>['name'=>'like[order_sn]']])?></li>
                    <li><?= \common\widgets\FormInput::widget(['name'=>'select|支付状态','extend'=>['name'=>'where[pay_status]','value'=>'','place'=>'所有','data'=>$this->params['pay_status']]])?></li>
                    <li><?= \common\widgets\FormInput::widget(['name'=>'select|订单状态','extend'=>['name'=>'where[order_status]','value'=>'','place'=>'所有','data'=>$this->params['order_status']]])?></li>
                    <li>
                        <?= $this->render('/iframe',['name'=>'searchbtn|搜索'])?>
                        <?= $this->render('/iframe',['name'=>'resetbtn|重置'])?>
                    </li>
                </ul>
            </div>
        </form>
    </div>
    <div class="col-sm-12 select-table table-striped">
        <table id="bootstrap-table"></table>
    </div>
</div>

<?php $this->beginBlock('script'); ?>
<script>
    $(function () {
        var edit_amount = Number('<?=$this->params['edit_amount']?>');
        bootUrl.url = "<?=\yii\helpers\Url::to(['order/index'])?>"
        var options = {
            modalName: "订单",
            sortName:'create_time',
            sortOrder: "desc",
            detailUrl: bootUrl.detailUrl,
            columns: [
                {field: 'id', title: 'ID'},
                {
                    field: '',
                    title: '订单信息',
                    formatter: function (value, row, index) {
                        var html = '';
                        html+=`<p>订单编号:${row.order_sn}</p>`;
                        html+=`<p>下单时间:${row.create_time}</p>`;
                        html+=`<p>支付时间:${row.pay_time}</p>`;
                        return html;
                    }
                },
                {
                    title: '会员信息',
                    field: 'status',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return row.user_html;
                    }
                },
                {
                    title: '商品信息',
                    field: 'good_html',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return value;
                    }
                },
                {
                    title: '商品数量',
                    field: 'total_num',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return value;
                    }
                },
                {
                    title: '佣金金额',
                    field: 'ca_brokerage',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return value;
                    }
                },
                {
                    title: '收货信息',
                    field: 'address',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return value;
                    }
                },
                {field: 'pay_status_name', title: '支付状态'},
                {field: 'order_status_name', title: '订单状态'},
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var html = `<a class="btn btn-success btn-xs" href="javascript:;" onclick="detail(${row.id})"><i class="fa fa-eye"></i>查看</a>`;
                        if (row.order_status==2&&row.delivery_method==1){
                            html += ` <a class="btn btn-info btn-xs" href="javascript:;" onclick="deliver(${row.order_sn})">发货</a>`
                        }
                        if (row.pay_status==0){
                            html += ` <a class="btn btn-warning btn-xs" href="javascript:;" onclick="cancel(${row.order_sn})">取消订单</a>`
                            html += ` <a class="btn btn-info btn-xs" href="javascript:;" onclick="editamount(${row.order_sn})">修改金额</a>`
                        }
                        return html;
                    }
                }
            ],
            onPostBody:function (data) {
                for (let i = 0; i < data.length; i++) {
                    if (document.getElementById('main_picture_'+data[i].id)){
                        new Viewer(document.getElementById('main_picture_'+data[i].id),{navbar:false,title:false});
                    }
                    if (document.getElementById('user_'+data[i].id)){
                        new Viewer(document.getElementById('user_'+data[i].id),{navbar:false,title:false});
                    }
                    if (document.getElementById('business_'+data[i].id)){
                        new Viewer(document.getElementById('business_'+data[i].id),{navbar:false,title:false});
                    }
                }
            }
        };
        $.table.init(options);
    });
    function detail(id) {
        var offsetWidth = document.body.offsetWidth-100
        var clientHeight = document.body.clientHeight-100
        $.operate.detail(id,offsetWidth,clientHeight)
    }
    function deliver(order_sn) {
        $.modal.confirm("确定发货【" + order_sn + "】吗？", function() {
            var url = "<?=\yii\helpers\Url::to(['deliver'])?>";
            var data = { "order_sn": order_sn };
            $.operate.submit(url, "post", "json", data);
        });
    }
    function cancel(order_sn) {
        table.set();
        $.modal.confirm("确定取消【" + order_sn + "】吗？", function() {
            var url = "<?=\yii\helpers\Url::to(['cancel'])?>";
            var data = { "order_sn": order_sn };
            $.operate.submit(url, "post", "json", data);
        });
    }
    function editamount(order_sn) {
        $.modal.open("修改金额", '<?=\yii\helpers\Url::to(['edit-amount'])?>?order_sn='+order_sn,'70','70',null,'%');
    }
</script>
<?php $this->endBlock(); ?>

